function add_flag(from,to){
	/*function adds a new option to the value sites*/	
	
	//Some restrictions about default values...

	//if you have some values and trying to add NONE or ALL
	//alert("Icinde :"+to[0].options.length+" var");
	if(to[0].options.length >=1 ){
			for(var i=0;i<from[0].options.length;i++){
				//alert("Eklenmeye calisilan :"+from[0].options[i].value);
				if (from[0].options[i].selected == true ){
					if((from[0].options[i].value=="ALL") || (from[0].options[i].value=="NONE")){
					//alert("Eklenmeye calisilan :"+from[0].options[i].value);
					alert("ALL or NONE are alone !");
					return;
		}
	}
			}
}


	//if you have alrady there ALL or NONE
	for(var j=0;j<to[0].options.length;j++){
		if((to[0].options[j].value=='NONE') || (to[0].options[j].value=="ALL")){
			alert("You can not add if you have already ALL or NONE");
			return ;
		}
}

	//When you grabbing the data you may have more than one option actually may have ALL NONE and others together
	var count_selected=0;
	var condition =false;
	
	for(var i=0;i<from[0].options.length;i++){
		//only selected ones
		if (from[0].options[i].selected==true){
			
			count_selected++;
			//if yo chosen the ALL or other
			if((from[0].options[i].value=="ALL") || (from[0].options[i].value=="NONE")){
				if (count_selected>1){
					alert("You can not add other options with ALL or NONE");
					return;
				}
				condition=true;
			}
		}
	}

	if ((count_selected>1) && (condition==true)){
		alert("You can not add other options with ALL or NONE");
		return;
	}
	
	//another annying control is to see if you have already chosen ALL or NONE with more than one

	for (var i=0;i<from[0].options.length;i++){
		if (from[0].options[i].selected==true){
			
			if(to[0].name=="comparer" && from[0].options[i].value=="NONE"){
				alert('NONE is not suitable for here!');
				continue;
			} 
				
			//search to see if you added it before
			var found=false;
			for(var j=0;j<to[0].options.length;j++){
				if(from[0].options[i].value==to[0].options[j].value){
				found=true;
				break;
				}
			}
			
			//Demekki zaten var eklmeye gerek yok yani
			if (found == true)
				continue;

			
			//the insertion process is that one
			var theop=document.createElement('option');
			theop.text=from[0].options[i].value;
			theop.selected=true;
			try{
				to[0].add(theop,null);
			}
			catch(ex){
				alert("Exception ortaya cikmis!");
			}
			
		}
	}

	//after we have taken them lets add to the real one


}

function remove_flag(toremove){
	/*that one removes the selected flags */
	for (var i=0;i<toremove[0].options.length;i++){

		if (toremove[0].options[i].selected==true){

			//alert("To remove "+toremove[0].options[i].value+toremove[0].options[i].index);
			toremove[0].remove(toremove[0].options[i].index); }
}
}

function control_submited_flag(seter,comparer){
	/*That one selects all the options that are included inthe boxes*/
	
	
	//alert('All are set!');
	//her ikisi de bos olabilir,bu secenek cunku...
	if(seter[0].options.length==0 && comparer[0].options.length==0){
		return true;
	}

	if(seter[0].options.length==0 || comparer[0].options.length==0){
		alert("Biri secildiyse digeri bos olamaz!");
		return false;
	}

	if(comparer[0].options.length==1 && comparer[0].options[0].value=='ALL'){
		//alert('ALL varsa sorun yoktur!');
		return true;

	}
	else{
	if (seter[0].options.length==1 && seter[0].options[0].value=='NONE'){
		//alert('Sagda none varsa sorun yoktur!');
		return true;
	}
	
	for (var i=0;i<seter[0].options.length;i++){
		if (find_val_option(comparer,seter[0].options[i].value)==false){
			alert('Sagdakilerin hepsi en azindan solda olmalidir!');
			return false;
			}
		}
	
	
	}

	if (select_submited(seter)!=true)
		return false;

	if (select_submited(comparer)!=true)
		return false;

	return true;//All passed succesful
}

function find_val_option(where,to_find){
	//Seraches the other box for the text we entered
	for (var i=0;i<where[0].options.length;i++){
			if(where[0].options[i].value==to_find)
				return true;//it as found
		}
	return false;
}



/*No usage for now*/
function select_submited(to_select){
	
	if (to_select[0].options.length > 0){
		for (var i=0;i<to_select[0].options.length;i++){
			to_select[0].options[i].selected==true;
			//alert(to_select[0].options[i].value);
		}
	}
	return true;

}

function remove_unwanted(s_man,c_man){
	//That one removes all the unwanted ones
	for (var j=0;j<4;j++){
	for (var i=0;i<s_man[0].options.length;i++){
			if (s_man[0].options[i].selected != true)
				s_man[0].remove(s_man[0].options[i].index);
				
			//alert(to_select[0].options[i].value);
		}
	}
	
	for (var j=0;j<4;j++){
	for (var i=0;i<c_man[0].options.length;i++){
			if (c_man[0].options[i].selected != true)
				c_man[0].remove(c_man[0].options[i].index);
				
			//alert(to_select[0].options[i].value);
		}
	}
	//alert("All should be removed !");
}

 
